

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Remind that the ACLMessage has been defined with the following template:
; (deftemplate ACLMessage 
;              (slot communicative-act) (slot sender) (multislot receiver) 
;              (slot reply-with) (slot in-reply-to) (slot envelope) 
;              (slot conversation-id) (slot protocol) 
;              (slot language) (slot ontology) (slot content) 
;              (slot encoding) (multislot reply-to) (slot reply-by))
; refer to Fipa2000 (www.fipa.org) for the description of the 
; ACLMessage parameters.
;
; Remind that Jade has also asserted for you the fact 
; (MyAgent (name <agentname)) 
;that is usefull to know the name of your agent
;
; Finally, remind that Jade has built a userfunction called send
; to send messages to other agents. There are two styles to call send:
; ?m <- (assert (ACLMessage (communicative-act inform) (receiver agent)))
; (send ?m)
; or, in alternative
; (send (assert (ACLMessage (communicative-act inform) (receiver agent))))
; The two following rules show the usage of both styles. One of the two
; rules can be used
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(import jade.*)


(deftemplate ACLMessage
              (slot communicative-act) (slot sender) (multislot
receiver)
              (slot reply-with) (slot in-reply-to) (slot envelope)
              (slot conversation-id) (slot protocol)
              (slot language) (slot ontology) (slot content)
              (slot encoding) (multislot reply-to) (slot reply-by))


;(deftemplate MyAgent (slot name))



;;;======================================================
;;;       
;;;     				 deftemplate for F(X) properties
;;;     
;;;======================================================		  

(deftemplate dimensiunea_sistemului (slot dimens (type INTEGER)))
(deftemplate jacobianul_sistemului (slot jacobian (type INTEGER)))
(deftemplate forma_sistemului (slot forma (type STRING)))
(deftemplate grad_linearitate_al_sistemului (slot grad_lin (type STRING)))
(deftemplate solutia_sistemului (slot solutie (type STRING)))

;;;======================================================
;;;       
;;;     				 define F(X) properties
;;;     
;;;======================================================		  
  ;(assert (dimensiunea_sistemului (dimens 3)))
  ;dimensiunea sistemului n poate avea orice valori : mica (n < 10), medie (10 < n < 50) , mare (50 < n < 500) sau foarte mare (500 < n)
  
   ;(assert (jacobianul_sistemului (jacobian 100)))
  ;jacobianul poate avea orice valori aproximative
  
  ;(assert (forma_sistemului (forma generala)))
  ; forma sistemului : generala , lacunara , diagonal_explicita , suma sau speciala
  
  ;(assert (grad_linearitate_al_sistemului (grad_lin oarecare)))
  ; gradul de linearitate al sistemului : oarecare sau slab_neliniar 
  
	

(deffunction send () )

;(defrule proposal
; "When a 'cfp' message arrives from an agent ?s, this rule asserts a 
;  'propose' message to the same sender and retract the just arrived message"
; ?m <- (ACLMessage (communicative-act CFP) (sender ?s) (content ?m) (receiver ?r))
; =>
; (send (assert (ACLMessage (communicative-act PROPOSE) (receiver ?s) (content ?c) )))
; (assert (ACLMessage (communicative-act PROPOSE) (sender ?r) (receiver ?s) (content ?c) ))  
; (retract ?m)
;)




;;;======================================================
;;;       
;;;     				 define rule for output solution
;;;     
;;;======================================================		  



;(printout t "Metoda recomandata este : " ?metoda " ." crlf))
;(defrule send-a-message
 ;"When a message is asserted whose sender is this agent, the message is
 ; sent and then retracted from the knowledge base."
 ;(MyAgent (name ?n))
 ;?m <- (ACLMessage (sender ?n))
; 
; =>
; (send ?m)
; (retract ?m))


;;;======================================================
;;;       
;;;     				 define rule for Newton clasica
;;;     
;;;======================================================	
(defrule cauta_NC
	(dimensiunea_sistemului  {dimens < 10})
	(jacobianul_sistemului {jacobian != 0})
	(forma_sistemului {forma == generala})
	(grad_linearitate_al_sistemului {grad_lin == oarecare})
	=>
	(assert (solutia_sistemului (solutie Newton_clasica)))
    (store RESULT 1)
    (printout t "The method is: Netwon Classic" crlf )
    (send "Newton Classic")
    
)	
  
;;;======================================================
;;;       
;;;     				 define rule for Newton discret
;;;     
;;;======================================================	
(defrule cauta_ND
	(dimensiunea_sistemului  {dimens     <  10 })
	(jacobianul_sistemului {jacobian != 0})
	(forma_sistemului {forma == generala})
	(grad_linearitate_al_sistemului {grad_lin == oarecare})
	=>
	(assert (solutia_sistemului (solutie Newton_discret)))
)	
;;;======================================================
;;;       
;;;     				 define rule for Newton simpl. gen.
;;;     
;;;======================================================	
(defrule cauta_NSG
	(dimensiunea_sistemului  {dimens < 50 && dimens > 10})
	(jacobianul_sistemului {jacobian != 0})
	(forma_sistemului {forma == generala})
	(grad_linearitate_al_sistemului {grad_lin == oarecare})
	=>
	(assert (solutia_sistemului (solutie Newton_simpl._gen.)))
)	
;;;======================================================
;;;       
;;;     				 define rule for Linii paralele
;;;     
;;;======================================================	
(defrule cauta_LP
	(dimensiunea_sistemului  {dimens < 500 && dimens > 50 })
	(jacobianul_sistemului {jacobian > 1000})
	(forma_sistemului {forma == generala})
	(grad_linearitate_al_sistemului {grad_lin == oarecare})
	=>
	(assert (solutia_sistemului (solutie Linii_paralele)))
)
;;;======================================================
;;;       
;;;     				 define rule for Secanta
;;;     
;;;======================================================	
(defrule cauta_SC
	(dimensiunea_sistemului  {dimens     <  10 })
	(jacobianul_sistemului {jacobian != 0})
	(forma_sistemului {forma == generala})
	(grad_linearitate_al_sistemului {grad_lin == oarecare})
	=>
	(assert (solutia_sistemului (solutie Secanta)))
)
;;;======================================================
;;;       
;;;     				 define rule for Steffensen
;;;     
;;;======================================================	
(defrule cauta_STF
	(dimensiunea_sistemului  {dimens     <  10 })
	(jacobianul_sistemului {jacobian != 0})
	(forma_sistemului {forma == generala})
	(grad_linearitate_al_sistemului {grad_lin == oarecare})
	=>
	(assert (solutia_sistemului (solutie Steffensen)))
)
;;;======================================================
;;;       
;;;     				 define rule for Broyden
;;;     
;;;======================================================	
(defrule cauta_BRD
	(dimensiunea_sistemului  {dimens > 10 && dimens < 500 })
	(jacobianul_sistemului {jacobian != 0})
	(forma_sistemului {forma == generala})
	(grad_linearitate_al_sistemului {grad_lin == oarecare})
	=>
	(assert (solutia_sistemului (solutie Broyden)))
)
;;;======================================================
;;;       
;;;     				 define rule for Frideman
;;;     
;;;======================================================	
(defrule cauta_FRI
    (dimensiunea_sistemului  {dimens > 50 && dimens < 500 })
	;;;(jacobianul_sistemului {jacobian != 0})
	(forma_sistemului {forma == lacunara})
	(grad_linearitate_al_sistemului {grad_lin == oarecare})
	=>
	(assert (solutia_sistemului (solutie Frideman)))
)
;;;======================================================
;;;       
;;;     				 define rule for Gradient conjugat
;;;     
;;;======================================================	
(defrule cauta_GRD
	(dimensiunea_sistemului  {dimens > 50 && dimens < 500 })
	;;;(jacobianul_sistemului {jacobian != 0})
	(forma_sistemului {forma == lacunara})
	(grad_linearitate_al_sistemului {grad_lin == oarecare})
	=>
	(assert (solutia_sistemului (solutie Gradient_conjugat)))
)
;;;======================================================
;;;       
;;;     				 define rule for SOR simpla
;;;     
;;;======================================================	
(defrule cauta_SORS
	(dimensiunea_sistemului  {dimens > 10 && dimens < 500 })
	(jacobianul_sistemului {jacobian  > 500})
	(forma_sistemului {forma == lacunara})
	(grad_linearitate_al_sistemului {grad_lin == slab_neliniara})
	=>
	(assert (solutia_sistemului (solutie SOR_simpla)))
)
(defrule cauta_SORS2
	(dimensiunea_sistemului  {dimens > 10 && dimens < 500 })
	(jacobianul_sistemului {jacobian  > 500})
	(forma_sistemului {forma == diagonal_explicita})
	(grad_linearitate_al_sistemului {grad_lin == slab_neliniar})
	=>
	(assert (solutia_sistemului (solutie SOR_simpla)))
)
;;;======================================================
;;;       
;;;     				 define rule for SOR generala
;;;     
;;;======================================================	
(defrule cauta_SORG
	(dimensiunea_sistemului  {dimens > 50 && dimens < 500 })
	;;;(jacobianul_sistemului {jacobian != 0})
	(forma_sistemului {forma == lacunara})
	(grad_linearitate_al_sistemului {grad_lin == slab_neliniar})
	=>
	(assert (solutia_sistemului (solutie SOR_generala)))
)
;;;======================================================
;;;       
;;;     				 define rule for ADI clasica
;;;     
;;;======================================================	
(defrule cauta_ADIC
	(dimensiunea_sistemului  {dimens > 10 && dimens < 500 })
	;;;(jacobianul_sistemului {jacobian != 0})
	(forma_sistemului {forma == suma})
	(grad_linearitate_al_sistemului {grad_lin == oarecare})
	=>
	(assert (solutia_sistemului (solutie ADI_clasica)))
)
;;;======================================================
;;;       
;;;     				 define rule for ADI Kellog
;;;     
;;;======================================================	
(defrule cauta_ADIK
	(dimensiunea_sistemului  {dimens > 10 && dimens < 50 })
	;;;(jacobianul_sistemului {jacobian != 0})
	(forma_sistemului {forma == suma})
	(grad_linearitate_al_sistemului {grad_lin == oarecare})
	=>
	(assert (solutia_sistemului (solutie ADI_Kellog)))
)
;;;======================================================
;;;       
;;;     				 define rule for Speciale
;;;     
;;;======================================================	

(defrule cauta_SPEC
	(dimensiunea_sistemului  {dimens > 0 })
		=>
	(assert (solutia_sistemului (solutie Speciale)))
)
;;;======================================================
;;;       
;;;     				 execute
;;;     
;;;======================================================		  

(defrule incomming-msg
   ( ACLMessage (sender ?s))
=>
(printout t "MESSAGE RECEIVED FROM " (?s getLocalName) crlf))


;(defrule solutie 
;    (MyAgent  (name ?agent))
;    
;(solutia_sistemului (solutie ?metoda)) 
;=> 
    ;(bind ?msg new ACLMessage)

    ;(?msg setContent ?metoda)
;    (send ?metoda)
;     (bind ?message (new jade.lang.acl.ACLMessage (get-member jade.lang.acl.ACLMessage INFORM)))

;  (?message setSender (?agent getAID)) ; take "my" agent as the sender
  
;  (?message addReceiver (MyAgent (name "Manes")))

;  (?message setContent  ?metoda) ; just copy the original content

;  (?agent send ?message)
;    (store T ?metoda))
    ;(?msg send))
    ;(send (assert (ACLMessage (communicative-act INFORM)(receiver "Manes")(content ?metoda)))))

(defrule solutie
   ; (MyAgent name "Manes") 
    (solutia_sistemului (solutie ?metoda))
    
=>
    ;(store RESULT ?metoda)
    (send ?metoda)
    )

(watch facts)
(watch all)
(reset) 

(run)  
; if you put run here, Jess is run before waiting for a message arrival,
; if you do not put (run here, the agent waits before for the arrival of the 
; first message and then runs Jess.








